class Solution {
public:
    int numberOfArithmeticSlices(vector<int>& nums) {
        const int m = nums.size();

        if(m < 3)
            return 0;

        int dp[m];
        dp[1] = dp[0] = 0;
        int sum = 0;
        for(int i = 2; i < m; ++i)
        {
            if(nums[i - 2] + nums[i] != nums[i - 1] * 2)
                dp[i] = 0;
            else
                dp[i] = dp[i - 1] + 1;
            sum += dp[i];
        }
        return sum;
    }
};
